package com.yunxin.core.infra.persistence.repository.channel;

import com.yunxin.core.domain.model.channel.ChannelPromotionCustomConfig;
import com.yunxin.core.domain.model.channel.ChannelPromotionCustomConfigRepository;
import com.yunxin.core.infra.persistence.converter.ChannelConvertor;
import com.yunxin.core.infra.persistence.entity.channel.ChannelPromotionCustomConfigDO;
import com.yunxin.core.infra.persistence.mapper.channel.ChannelPromotionCustomConfigExtendMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

/**
 * @author zero°
 * @since 2023-07-17
 */
@Repository
@RequiredArgsConstructor
public class ChannelPromotionCustomConfigRepositoryImpl implements ChannelPromotionCustomConfigRepository {

    private final ChannelPromotionCustomConfigExtendMapper promotionCustomConfigExtendMapper;

    private final ChannelConvertor channelConvertor;
    @Override
    public boolean saveChannelPromotionCustomConfig(ChannelPromotionCustomConfig channelPromotionCustomConfig) {
        ChannelPromotionCustomConfigDO channelPromotionCustomConfigDO = channelConvertor.formChannelPromotionCustomConfig(channelPromotionCustomConfig);
        int count = promotionCustomConfigExtendMapper.insertSelective(channelPromotionCustomConfigDO);
        return count > 0;
    }

    @Override
    public boolean updateChannelPromotionCustomConfig(ChannelPromotionCustomConfig channelPromotionCustomConfig) {
        ChannelPromotionCustomConfigDO channelPromotionCustomConfigDO = channelConvertor.formChannelPromotionCustomConfig(channelPromotionCustomConfig);
        int count = promotionCustomConfigExtendMapper.updateByPrimaryKeySelective(channelPromotionCustomConfigDO);
        return count > 0;
    }

    @Override
    public ChannelPromotionCustomConfig getByPromotionId(Long promotionId) {
        ChannelPromotionCustomConfigDO channelPromotionCustomConfigDO = promotionCustomConfigExtendMapper.selectByPromotionId(promotionId);
        return channelConvertor.toChannelPromotionCustomConfig(channelPromotionCustomConfigDO);
    }
}
